

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;


public class Taula extends JPanel {
 
    JPanel panela = new JPanel();
    
	Vector<String> zutabeIzenak; 

	MyTableModel modeloa = new MyTableModel();
	
	
    public Taula(Vector<String> izenak) {
        super(new GridLayout(2,0));
        zutabeIzenak= new Vector<String>();
        zutabeIzenak = izenak;
        JTable table = new JTable(modeloa);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);

        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);

        //Add the scroll pane to this panel.
        add(scrollPane);
    }

    class MyTableModel extends AbstractTableModel {
    	       
        Vector<Objetua> datuak = new Vector<Objetua>();
        
    	public MyTableModel() {  
    		
    	}


		public int getColumnCount() {
            return zutabeIzenak.size();
        }

        public int getRowCount() {
            return datuak.size();
        }

        public String getColumnName(int col) {
            return zutabeIzenak.get(col);
        }

        public Object getValueAt(int row, int col) {
        
            return datuak.elementAt(row).elementAt(col);
        	
        }


        public boolean isCellEditable(int row, int col) {
        
            return true;
            
        }

        public void setValueAt(Object value, int row, int col) {

            datuak.get(row).setElementAt(value, col);
            fireTableCellUpdated(row, col);

        }

     
    }

    public void lerroaGehitu(Objetua o) {
		
		modeloa.datuak.add(o);
		modeloa.fireTableDataChanged();

	}
	

}
